import { INCREASE, DECREASE } from '../actionType'

// 仓库数据
export interface IState {
  count: number
}
interface IAction {
  type: symbol
  count?: number
}

const defaultState: IState = {
  count: 2
}

const reducer = (state: IState = defaultState, action: IAction) => {
  // reducer 不允许直接修改 state的数据
  const newState = { ...state }
  const { count = 0 } = state
  const { count: newCount = 0 } = action
  switch (action.type) {
    case INCREASE:
      newState.count = count + newCount
      break
    case DECREASE:
      newState.count = count - newCount
      break
    default:
      console.log('count没有发现type', action.type)
      return state
  }
  return newState
}

export default reducer
